#include<bits/stdc++.h>
using namespace std;
const int N = 100+5;
typedef pair<int, int> pi; // start, end
pi arr[N];
int n;
int solve() {
  sort(arr, arr+n, [](pi a, pi b) {
        if(a.second == b.second) {
          return a.first<b.first;
        }
        return a.second<b.second;
      });
  int now = arr[0].second;
  int ans = 1;
  for(int i=1; i<n; ++i) {
    if(arr[i].first >= now) {
      now = arr[i].second;
      ans++;
    }
  }
  cout<<ans<<'\n';
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  while(cin>>n) {
    if(n==0) break;
    for(int i=0; i<n; ++i) cin>>arr[i].first>>arr[i].second;
    solve();
  }
  return 0;
}

